package org.db.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.db.Manager;
import org.db.dao.LageskizzenGVPDAO;
import org.db.dao.LageskizzenWeichenDAO;
import org.db.dao.change.AddProjektElement;
import org.db.dao.change.RemoveProjektElement;
import org.db.dao.change.UpdateProjektElement;

/**
 * 
 * @author Lutz
 */
public class LageskizzenDialog extends CloseCommitDialog
		implements
			ActionListener,
			FocusListener,
			KeyListener,
			MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3229112587162076537L;

	private LageskizzenGVPDAO lastAddedDao;

	private LageskizzenGVPDAO gvpElement2Edit = null;

	private LageskizzenWeichenDAO weichenElement2Edit = null;

	private DecimalFormat format1 = new DecimalFormat("0");

	public LageskizzenDialog(JDialog owner) {
		super(owner);
		setModal(true);
		setTitle("Lageskizze");
		initComponents();
		// setSize(Toolkit.getDefaultToolkit().getScreenSize());
	}

	private static final String GVPException = "Bitte geben Sie eine Punktnummer, eine Stationierung und ggf. ein Quermaß zum GVP ein!";

	private static final String WeichenException = "Bitte geben Sie die Stationierung und die Bezeichnung der Weiche ein!";

	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jTextPktNrLi = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		jTextQuerPktLi = new DoubleTextField();
		jLabel6 = new javax.swing.JLabel();
		jTextStationLi = new DoubleTextField();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		jTextHoeheLi = new IntegerTextField(true);
		jLabel10 = new javax.swing.JLabel();
		jTextQuerLiGleis = new DoubleTextField();
		jLabel12 = new javax.swing.JLabel();
		jTextQuerReGleis = new DoubleTextField();
		jLabel14 = new javax.swing.JLabel();
		jLabel15 = new javax.swing.JLabel();
		jLabel16 = new javax.swing.JLabel();
		jLabel17 = new javax.swing.JLabel();
		jLabel18 = new javax.swing.JLabel();
		jTextPktNrRe = new javax.swing.JTextField();
		jTextStationRe = new DoubleTextField();
		jLabel21 = new javax.swing.JLabel();
		jTextHoeheRe = new IntegerTextField(true);
		jLabel23 = new javax.swing.JLabel();
		jLabel24 = new javax.swing.JLabel();
		jLabel26 = new javax.swing.JLabel();
		jLabel27 = new javax.swing.JLabel();
		jTextWeichenNr = new javax.swing.JTextField();
		jLabel28 = new javax.swing.JLabel();
		jTextWeichenBez = new javax.swing.JTextField();
		jLabel29 = new javax.swing.JLabel();
		jTextStationWeiche = new DoubleTextField();
		jButtonNextGVP = new javax.swing.JButton();
		jButtonOK = new javax.swing.JButton();
		jButtonCancel = new javax.swing.JButton();
		jLabel30 = new javax.swing.JLabel();
		jLabel31 = new javax.swing.JLabel();
		jLabel32 = new javax.swing.JLabel();
		jLabel33 = new javax.swing.JLabel();
		jScrollPane2 = new javax.swing.JScrollPane();
		jScrollPane1 = new javax.swing.JScrollPane();
		tableGVP = new LageskizzenGVPTable();
		tableGVP.addKeyListener(this);
		tableGVP.addMouseListener(this);
		tableWeiche = new LageskizzenWeichenTable();
		tableWeiche.addKeyListener(this);
		tableWeiche.addMouseListener(this);
		jButtonNextWeiche = new javax.swing.JButton();
		jSeparator2 = new javax.swing.JSeparator();
		jSeparator3 = new javax.swing.JSeparator();
		jSeparator1 = new javax.swing.JSeparator();
		jSeparator4 = new javax.swing.JSeparator();
		jSeparator5 = new javax.swing.JSeparator();

		jButtonNextWeiche.setFont(new java.awt.Font("Tahoma", 1, 12));
		jButtonNextWeiche.setText("Weiche hinzufügen");
		jButtonNextWeiche
				.setToolTipText("Speichert Daten in Liste und löscht Eingabefelder für nächstes Element.");
		jButtonNextWeiche.addActionListener(this);
		jButtonNextWeiche.addKeyListener(this);

		setPreferredSize(new java.awt.Dimension(1200, 800));
		setResizable(false);

		jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
		jLabel1.setText("Lageskizze");

		jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel2.setText("[");

		jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel3.setText("Gleisvermarkung:");
		jLabel3.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(0, 0, 0)));
		jLabel3.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
		jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

		jTextPktNrLi.setToolTipText("Punktnummer linkes Gleis (im Kästchen)");

		jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel4.setText("linker GVP");

		jTextQuerPktLi
				.setToolTipText("z.B 11.670, rechts neben dem GVP- Symbol");

		jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel6.setText("Quermaß linker GVP");

		jTextStationLi.setToolTipText("Stationierung des rechten GVP");
		Double stationAnf = (Manager.getInstance().getGleisElemente()
				.get(returnValue).getAnfangsStation() + 60);
		jTextStationLi.setText(stationAnf.toString());

		jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel7.setText("]");

		jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel8.setText("Höhenabsetzmaß");

		jTextHoeheLi.setToolTipText("z.B. -587, links neben dem GVP- Symbol");
		jTextHoeheLi.setText("-");

		jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel10.setText("Quermaße linkes Gleis");

		jTextQuerLiGleis
				.setToolTipText("Quermaß li Gleis(z.B. 8.456), rechts neben Verbindungslinie der GVP's");

		jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel12.setText("Quermaße rechtes Gleis");

		jTextQuerReGleis
				.setToolTipText("Quermaß re Gleis(z.B. 3.657), rechts neben Verbindungslinie der GVP's");

		jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel14.setText("(");

		jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel15.setText("(");

		jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel16.setText(")");

		jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel17.setText(")");

		jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel18.setText("[");

		jTextPktNrRe.setToolTipText("Punktnummer rechtes Gleis (im Kästchen)");

		jTextStationRe.setToolTipText("Stationierung des GVP");
		jTextStationRe.setText(stationAnf.toString());

		jLabel21.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel21.setText("Höhenabsetzmaß");

		jTextHoeheRe.setToolTipText("z.B. -587, links neben dem GVP- Symbol");
		jTextHoeheRe.setText("-");

		jLabel23.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel23.setText("rechter GVP");

		jLabel24.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel24.setText("]");

		jLabel26.setFont(new java.awt.Font("Tahoma", 1, 14));
		jLabel26.setText("Weichen:");
		jLabel26.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(0, 0, 0)));
		jLabel26.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
		jLabel26.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

		jLabel27.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel27.setText("Weichennummer:");

		jTextWeichenNr.setToolTipText("Wenn bekannt, Weichennummer eintragen.");

		jLabel28.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel28.setText("Bezeichnung:");

		jTextWeichenBez.setToolTipText("z.B. 49-190-1:9");

		jLabel29.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel29.setText("WA:");

		jTextStationWeiche
				.setToolTipText("angegebene Stationierung zur Weiche");

		jButtonNextGVP.setFont(new java.awt.Font("Tahoma", 1, 12));
		jButtonNextGVP.setText("GVP hinzufügen");
		jButtonNextGVP
				.setToolTipText("Speichert Daten in Liste und löscht Eingabefelder für nächstes Element.");
		jButtonNextGVP.addActionListener(this);
		jButtonNextGVP.addKeyListener(this);

		jButtonOK.setFont(new java.awt.Font("Tahoma", 1, 12));
		jButtonOK.setText("Eingabe beenden");
		jButtonOK
				.setToolTipText("Prüfen und Speichern der Eingaben. Zurück zum Auswahlfenster.");
		jButtonOK.addActionListener(this);
		jButtonOK.addKeyListener(this);

		jButtonCancel.setFont(new java.awt.Font("Tahoma", 1, 12));
		jButtonCancel.setText("Abbrechen");
		jButtonCancel
				.setToolTipText("Verwerfen der Eingaben, zurück zum Auswahlfenster.");
		jButtonCancel.addActionListener(this);
		jButtonCancel.addKeyListener(this);

		jLabel30.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel30.setText(")");

		jLabel31.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel31.setText("(");

		jLabel32.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel32.setText("(");

		jLabel33.setFont(new java.awt.Font("Tahoma", 1, 12));
		jLabel33.setText(")");

		jScrollPane1.setViewportView(tableGVP);
		jScrollPane2.setViewportView(tableWeiche);

		jSeparator2.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 4));

		jSeparator3.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 6));

		jSeparator1.setBackground(new java.awt.Color(0, 0, 0));
		jSeparator1.setForeground(new java.awt.Color(0, 0, 0));
		jSeparator1.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 5));

		jSeparator4.setBackground(new java.awt.Color(0, 0, 0));
		jSeparator4.setForeground(new java.awt.Color(0, 0, 0));
		jSeparator4.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 5));

		jSeparator5.setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 10));

		JPanel wrapper = new JPanel();
		// javax.swing.GroupLayout layout = new
		// javax.swing.GroupLayout(getContentPane());
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(wrapper);
		wrapper.setLayout(layout);
		getContentPane().add(new JScrollPane(wrapper));
		// getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(204, 204, 204)
								.addComponent(jLabel30,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										2630, Short.MAX_VALUE)
								.addContainerGap())
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(jSeparator2,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										509,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(2335, Short.MAX_VALUE))
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(jSeparator3,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										509,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap())
				.addGroup(
						layout.createSequentialGroup().addContainerGap()
								.addComponent(jLabel1)
								.addContainerGap(2737, Short.MAX_VALUE))
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(jLabel26,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										75,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(2759, Short.MAX_VALUE))
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING)
												.addGroup(
														javax.swing.GroupLayout.Alignment.LEADING,
														layout.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																false)
																.addComponent(
																		jScrollPane2,
																		javax.swing.GroupLayout.Alignment.LEADING,
																		0,
																		0,
																		Short.MAX_VALUE)
																.addGroup(
																		javax.swing.GroupLayout.Alignment.LEADING,
																		layout.createSequentialGroup()
																				.addGroup(
																						layout.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																								.addComponent(
																										jLabel29)
																								.addComponent(
																										jLabel28)
																								.addComponent(
																										jLabel27))
																				.addPreferredGap(
																						javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																				.addGroup(
																						layout.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																								.addGroup(
																										layout.createSequentialGroup()
																												.addGroup(
																														layout.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																																.addComponent(
																																		jTextWeichenNr,
																																		javax.swing.GroupLayout.PREFERRED_SIZE,
																																		110,
																																		javax.swing.GroupLayout.PREFERRED_SIZE)
																																.addComponent(
																																		jTextWeichenBez,
																																		javax.swing.GroupLayout.PREFERRED_SIZE,
																																		110,
																																		javax.swing.GroupLayout.PREFERRED_SIZE))
																												.addGap(48,
																														48,
																														48)
																												.addComponent(
																														jButtonNextWeiche))
																								.addComponent(
																										jTextStationWeiche,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										110,
																										javax.swing.GroupLayout.PREFERRED_SIZE))))
												.addComponent(
														jScrollPane1,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														1130,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addContainerGap(1704, Short.MAX_VALUE))
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addContainerGap()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING)
																												.addComponent(
																														jLabel4)
																												.addComponent(
																														jLabel3,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														136,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel8))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jTextHoeheLi,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														56,
																														Short.MAX_VALUE)
																												.addComponent(
																														jTextStationLi,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														56,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel32)))
																				.addGroup(
																						javax.swing.GroupLayout.Alignment.TRAILING,
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jLabel14)
																												.addComponent(
																														jLabel15))
																								.addGap(51,
																										51,
																										51)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jLabel17)
																												.addComponent(
																														jLabel16))
																								.addGap(12,
																										12,
																										12))))
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addGap(35, 35,
																		35)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						jLabel21)
																				.addComponent(
																						jLabel23))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jTextHoeheRe,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						61,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabel31)
																				.addComponent(
																						jTextStationRe,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						57,
																						javax.swing.GroupLayout.PREFERRED_SIZE))))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(15, 15,
																		15)
																.addComponent(
																		jLabel2)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		jTextPktNrLi,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		47,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		jLabel7,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		11,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addContainerGap())
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jSeparator1,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						9,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jSeparator5,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						8,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										jTextQuerPktLi,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										64,
																										javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(
																										jLabel6))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING,
																												false)
																												.addComponent(
																														jTextQuerReGleis,
																														javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jTextQuerLiGleis,
																														javax.swing.GroupLayout.Alignment.LEADING,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														62,
																														Short.MAX_VALUE))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														jLabel12)
																												.addComponent(
																														jLabel10)))))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jSeparator4,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		9,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(2609,
																		2609,
																		2609))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel33,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		2608,
																		Short.MAX_VALUE)
																.addContainerGap())
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel18)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		jTextPktNrRe,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		47,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(91,
																										91,
																										91)
																								.addComponent(
																										jButtonNextGVP,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										150,
																										javax.swing.GroupLayout.PREFERRED_SIZE))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(
																										jLabel24,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										15,
																										javax.swing.GroupLayout.PREFERRED_SIZE)))
																.addGap(34, 34,
																		34)
																.addComponent(
																		jButtonOK,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		150,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		jButtonCancel,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		150,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addContainerGap(
																		2071,
																		Short.MAX_VALUE)))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addContainerGap()
																.addComponent(
																		jLabel1)
																.addGap(11, 11,
																		11)
																.addComponent(
																		jLabel3)
																.addGap(22, 22,
																		22)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						jLabel4)
																				.addComponent(
																						jTextStationLi,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabel2)
																				.addComponent(
																						jTextPktNrLi,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabel7))
																.addGap(39, 39,
																		39)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						jLabel32)
																				.addComponent(
																						jLabel33))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addGroup(
																						layout.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																								.addComponent(
																										jLabel8)
																								.addComponent(
																										jTextHoeheLi,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										javax.swing.GroupLayout.DEFAULT_SIZE,
																										javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addComponent(
																										jTextQuerPktLi,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										javax.swing.GroupLayout.DEFAULT_SIZE,
																										javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addComponent(
																										jLabel6))
																				.addComponent(
																						jSeparator1,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						10,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGap(18, 18,
																		18)
																.addComponent(
																		jSeparator2,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(5,
																										5,
																										5)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jLabel14)
																												.addComponent(
																														jLabel16))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																										66,
																										Short.MAX_VALUE)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jLabel15)
																												.addComponent(
																														jLabel17)))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jTextQuerLiGleis,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel10))
																								.addGap(47,
																										47,
																										47)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jTextQuerReGleis,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel12)))
																				.addComponent(
																						jSeparator5,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						92,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGap(18, 18,
																		18)
																.addComponent(
																		jSeparator3,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(7, 7, 7)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jTextHoeheRe,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel21))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jLabel30)
																												.addComponent(
																														jLabel31))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																										30,
																										Short.MAX_VALUE)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.BASELINE)
																												.addComponent(
																														jTextStationRe,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel23)
																												.addComponent(
																														jLabel18)
																												.addComponent(
																														jTextPktNrRe,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addComponent(
																														jLabel24))
																								.addGap(12,
																										12,
																										12))
																				.addComponent(
																						jSeparator4,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						10,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGap(22, 22,
																		22))
												.addGroup(
														layout.createSequentialGroup()
																.addGap(418,
																		418,
																		418)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						jButtonNextGVP,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						33,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jButtonOK,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						33,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jButtonCancel,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						33,
																						javax.swing.GroupLayout.PREFERRED_SIZE))))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jScrollPane1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										106,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGap(18, 18, 18)
								.addComponent(jLabel26)
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel29)
												.addComponent(
														jTextStationWeiche,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														jTextWeichenBez,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel28))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														jTextWeichenNr,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel27)
												.addComponent(
														jButtonNextWeiche,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														33,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(18, 18, 18)
								.addComponent(jScrollPane2,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										107,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGap(299, 299, 299)));

		validateInput();
		continueInput();
		isValidSession();
		pack();
	}

	public int showLageskizzenDialog() {
		setVisible(true);
		return returnValue;
	}

	/**
	 * Vorbereiten der Textfelder für nächsten GVP
	 */
	private void continueInput() {
		if (!tableGVP.isEmpty()) {
			lastAddedDao = Manager.getInstance().getLageskizzenGVPs().last();
			if (Integer.valueOf(lastAddedDao.gethoehenmaßGVPLinks()) != null) {
				jTextHoeheLi.setText(Integer.valueOf(
						lastAddedDao.gethoehenmaßGVPLinks()).toString());
			} else {
				jTextHoeheLi.setText("-");
			}
			if (Integer.valueOf(lastAddedDao.gethoehenmaßGVPRechts()) != null) {
				jTextHoeheRe.setText(Integer.valueOf(
						lastAddedDao.gethoehenmaßGVPRechts()).toString());
			} else {
				jTextHoeheRe.setText("-");
			}
			if (lastAddedDao.getpunktNrGVPLinks() != null) {
				jTextPktNrLi.setText(lastAddedDao.getpunktNrGVPLinks());
			} else {
				jTextPktNrLi.setText("");
			}
			if (lastAddedDao.getpunktNrGVPRechts() != null) {
				jTextPktNrRe.setText(lastAddedDao.getpunktNrGVPRechts());
			} else {
				jTextPktNrRe.setText("");
			}
			if (Double.valueOf(lastAddedDao.getquerGleisLinks()) != null) {
				jTextQuerLiGleis.setText(Double.valueOf(
						lastAddedDao.getquerGleisLinks()).toString());
			} else {
				jTextQuerLiGleis.setText("");
			}
			if (Double.valueOf(lastAddedDao.getquerGleisRechts()) != null) {
				jTextQuerReGleis.setText(Double.valueOf(
						lastAddedDao.getquerGleisRechts()).toString());
			} else {
				jTextQuerReGleis.setText("");
			}
			if (Double.valueOf(lastAddedDao.getquerGVPLinks()) != null) {
				jTextQuerPktLi.setText(Double.valueOf(
						lastAddedDao.getquerGVPLinks()).toString());
			} else {
				jTextQuerPktLi.setText("");
			}
			if (Double.valueOf(lastAddedDao.getstationGVPLinks()) != null) {
				jTextStationLi.setText(Double.valueOf(
						lastAddedDao.getstationGVPLinks()).toString());
			} else {
				jTextStationLi.setText("");
			}
			if (Double.valueOf(lastAddedDao.getstationGVPRechts()) != null) {
				jTextStationRe.setText(Double.valueOf(
						lastAddedDao.getstationGVPRechts()).toString());
			} else {
				jTextStationRe.setText("");
			}
			clearInputGVP();
			jTextPktNrLi.requestFocusInWindow();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == jButtonOK) {
			if (isValidSession()) {
				// Änderungen in XML-Datei übernehmen
				Manager.getInstance().applyChanges();
				setVisible(false);
				dispose();
			} else {
				JOptionPane.showMessageDialog(this,
						"Bitte überprüfen Sie die gelben Fehler!");
			}
		} else if (e.getSource() == jButtonCancel) {
			returnValue = JOptionPane.CANCEL_OPTION;
			askForClosing();

		} else if (e.getSource() == jButtonNextGVP) {
			if (isValidInputGVP()) {

				String punktNrGVPLinks = (String) (!jTextPktNrLi.getText()
						.isEmpty() ? jTextPktNrLi.getText() : "");
				String punktNrGVPRechts = (String) (!jTextPktNrRe.getText()
						.isEmpty() ? jTextPktNrRe.getText() : "");
				double stationGVPLinks = !jTextStationLi.getText().isEmpty()
						? Double.valueOf(jTextStationLi.getText())
						: 0;
				double stationGVPRechts = !jTextStationRe.getText().isEmpty()
						? Double.valueOf(jTextStationRe.getText())
						: 0;
				int hoehenmaßGVPLinks = !jTextHoeheLi.getText().equals("-")
						? Integer.valueOf(jTextHoeheLi.getText())
						: 0;
				int hoehenmaßGVPRechts = !jTextHoeheRe.getText().equals("-")
						? Integer.valueOf(jTextHoeheRe.getText())
						: 0;
				double querGVPLinks = !jTextQuerPktLi.getText().isEmpty()
						? Double.valueOf(jTextQuerPktLi.getText())
						: 0;
				double querGleisLinks = !jTextQuerLiGleis.getText().isEmpty()
						? Double.valueOf(jTextQuerLiGleis.getText())
						: 0;
				double querGleisRechts = !jTextQuerReGleis.getText().isEmpty()
						? Double.valueOf(jTextQuerReGleis.getText())
						: 0;
				double gleisabstand = !jTextQuerLiGleis.getText().isEmpty()
						&& !jTextQuerReGleis.getText().isEmpty()
						? querGleisLinks - querGleisRechts
						: 0;
				if (gleisabstand <= 3 && gleisabstand > 0
						&& !tableGVP.isEmpty()) {
					gleisabstand = lastAddedDao.getgleisabstand();
				}

				LageskizzenGVPDAO gvpDAO = new LageskizzenGVPDAO(
						punktNrGVPLinks, stationGVPLinks, hoehenmaßGVPLinks,
						querGVPLinks, punktNrGVPRechts, stationGVPRechts,
						hoehenmaßGVPRechts, querGleisLinks, querGleisRechts,
						gleisabstand);
				if (gvpElement2Edit != null) {
					tableGVP.replaceGVPElement(gvpElement2Edit, gvpDAO);
					Manager.getInstance().addProjektChange(
							new UpdateProjektElement(gvpElement2Edit, gvpDAO));
					gvpElement2Edit = null;
				} else {
					tableGVP.addLageskizzenGVP(gvpDAO);
					Manager.getInstance().addProjektChange(
							new AddProjektElement(gvpDAO));
				}

				clearInputGVP();
				returnValue = JOptionPane.OK_OPTION;
				lastAddedDao = gvpDAO;
				validateInput();
				isValidSession();
			}

		}

		else if (e.getSource() == jButtonNextWeiche) {
			if (isValidInputWeiche()) {
				double stationWeiche = !jTextStationWeiche.getText().isEmpty()
						? Double.valueOf(jTextStationWeiche.getText())
						: 0;
				String nummerWeiche = (String) (!jTextWeichenNr.getText()
						.isEmpty() ? jTextWeichenNr.getText() : "");
				String bezWeiche = (String) (!jTextWeichenBez.getText()
						.isEmpty() ? jTextWeichenBez.getText() : "");
				LageskizzenWeichenDAO weichenDAO = new LageskizzenWeichenDAO(
						stationWeiche, nummerWeiche, bezWeiche);
				if (weichenElement2Edit != null) {
					tableWeiche.replaceWeichenElement(weichenElement2Edit,
							weichenDAO);
					Manager.getInstance().addProjektChange(
							new UpdateProjektElement(weichenElement2Edit,
									weichenDAO));
					weichenElement2Edit = null;
				} else {
					tableWeiche.addLageskizzenWeiche(weichenDAO);
					Manager.getInstance().addProjektChange(
							new AddProjektElement(weichenDAO));
				}

				clearInputWeiche();
				isValidSession();
			}
		}
	}

	/**
	 * Erzwingen von mindestens einer kompletten Eingabe zu den GVP's
	 */
	private void validateInput() {
		jButtonOK.setEnabled(!tableGVP.isEmpty());
	}

	/**
	 * Leeren und Vorbereiten der Textfelder für folgenden GVP
	 */
	private void clearInputGVP() {
		jTextQuerLiGleis.setText("");
		jTextQuerPktLi.setText("");
		jTextQuerReGleis.setText("");
		jTextHoeheLi.setText("-");
		jTextHoeheRe.setText("-");
		Double stationLiNeu = !jTextStationLi.getText().isEmpty() ? Double
				.valueOf(jTextStationLi.getText()) + 60 : 0;
		if (!jTextStationLi.getText().isEmpty()) {
			jTextStationLi.setText(format1.format((stationLiNeu)));
		}
		jTextStationLi.requestFocusInWindow();
		Double stationReNeu = !jTextStationRe.getText().isEmpty() ? Double
				.valueOf(jTextStationRe.getText()) + 60 : 0;
		if (!jTextStationRe.getText().isEmpty()) {
			jTextStationRe.setText(format1.format((stationReNeu)));
		}
	}

	/**
	 * Leeren der Textfelder
	 */
	private void clearInputWeiche() {
		jTextStationWeiche.setText("");
		jTextWeichenBez.setText("");
		jTextWeichenNr.setText("");
		jTextStationLi.requestFocusInWindow();
	}

	/**
	 * Test ob die Änderungen in der aktuellen Sitzung gültig sind.
	 * 
	 * @return
	 */
	private boolean isValidSession() {
		tableGVP.resetHighlighting();
		tableWeiche.resetHighlighting();
		List<LageskizzenGVPDAO> GVPElemente = tableGVP.getGVPElemente();
		List<LageskizzenWeichenDAO> WeichenElemente = tableWeiche
				.getWeichenElemente();
		LageskizzenGVPDAO el1;
		LageskizzenGVPDAO el2;
		LageskizzenWeichenDAO elw1;
		LageskizzenWeichenDAO elw2;
		for (int i = 0; i < GVPElemente.size() - 1; i++) {
			el1 = GVPElemente.get(i);
			el2 = GVPElemente.get(i + 1);
			if (Math.abs(el1.getstationGVPLinks() - el2.getstationGVPLinks()) > 120) {
				tableGVP.highlightCell(i, 1);
				tableGVP.highlightCell(i + 1, 1);
				return false;
			} else if (Math.abs(el1.getstationGVPRechts()
					- el2.getstationGVPRechts()) > 120) {
				tableGVP.highlightCell(i, 5);
				tableGVP.highlightCell(i + 1, 5);
				return false;
				// } else if
				// (Math.abs(el1.getgleisabstand()-el2.getgleisabstand()) >
				// 0.01) {
				// tableGVP.highlightCell1(i, 9);
				// tableGVP.highlightCell1(i+1, 9);
				// return false;
			} else if (el1.getstationGVPLinks() == el2.getstationGVPLinks()) {
				tableGVP.highlightCell(i, 1);
				tableGVP.highlightCell(i + 1, 1);
				return false;
			} else if (el1.getstationGVPRechts() == el2.getstationGVPRechts()) {
				tableGVP.highlightCell(i, 5);
				tableGVP.highlightCell(i + 1, 5);
				return false;
			} else if (el1.getpunktNrGVPLinks()
					.equals(el2.getpunktNrGVPLinks())) {
				tableGVP.highlightCell(i, 0);
				tableGVP.highlightCell(i + 1, 0);
				return false;
			} else if (el1.getpunktNrGVPRechts().equals(
					el2.getpunktNrGVPRechts())) {
				tableGVP.highlightCell(i, 4);
				tableGVP.highlightCell(i + 1, 4);
				return false;
			}
		}
		for (int i = 0; i < WeichenElemente.size() - 1; i++) {
			elw1 = WeichenElemente.get(i);
			elw2 = WeichenElemente.get(i + 1);
			if (elw1.getstationWeiche() == elw2.getstationWeiche()) {
				tableWeiche.highlightCell(i, 0);
				tableWeiche.highlightCell(i + 1, 0);
				return false;
			}
		}
		return true;
	}

	/**
	 * Test ob die aktuellen Eingaben für GVP gültig sind.
	 * 
	 * @return
	 */
	private boolean isValidInputGVP() {
		if (!jTextStationLi.getText().isEmpty()) {
			if (jTextPktNrLi.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
			if (jTextHoeheLi.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		}
		if (!jTextStationRe.getText().isEmpty()) {
			if (jTextPktNrRe.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
			if (jTextHoeheRe.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		}
		if (!jTextPktNrLi.getText().isEmpty()) {
			if (jTextStationLi.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		}
		if (!jTextPktNrRe.getText().isEmpty()) {
			if (jTextStationRe.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, GVPException,
						"Angaben GVP", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		}
		if (jTextStationLi.getText().isEmpty()
				&& jTextStationRe.getText().isEmpty()) {
			JOptionPane.showMessageDialog(this, GVPException, "Angaben GVP",
					JOptionPane.WARNING_MESSAGE);
			return false;
		}
		return true;
	}

	/**
	 * Test ob die aktuellen Eingaben für Weiche gültig sind.
	 * 
	 * @return
	 */
	private boolean isValidInputWeiche() {
		if (!jTextStationWeiche.getText().isEmpty()) {
			if (jTextWeichenBez.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, WeichenException,
						"Angaben zur Weiche", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		} else if (!jTextWeichenBez.getText().isEmpty()) {
			if (jTextStationWeiche.getText().isEmpty()) {
				JOptionPane.showMessageDialog(this, WeichenException,
						"Angaben zur Weiche", JOptionPane.WARNING_MESSAGE);
				return false;
			}
		}
		return true;
	}

	/**
	 * Löschen der ausgewählten Reihe der Tabelle
	 */
	private void deleteSelectedRowGVP() {
		int selectedRowIndex = tableGVP.getSelectedRow();
		if (selectedRowIndex > -1) {
			LageskizzenGVPDAO removedDAO = tableGVP
					.removeGVPElement(selectedRowIndex);
			Manager.getInstance().addProjektChange(
					new RemoveProjektElement(removedDAO));
		}

	}

	/**
	 * Löschen der ausgewählten Reihe der Tabelle
	 */
	private void deleteSelectedRowWeiche() {
		int selectedRowIndex = tableWeiche.getSelectedRow();
		if (selectedRowIndex > -1) {
			LageskizzenWeichenDAO removedDAO = tableWeiche
					.removeWeichenElement(selectedRowIndex);
			Manager.getInstance().addProjektChange(
					new RemoveProjektElement(removedDAO));
		}

	}

	private int returnValue = 0;

	private javax.swing.JButton jButtonCancel;

	private javax.swing.JButton jButtonNextGVP;

	private javax.swing.JButton jButtonOK;

	private javax.swing.JButton jButtonNextWeiche;

	private javax.swing.JLabel jLabel1;

	private javax.swing.JLabel jLabel10;

	private javax.swing.JLabel jLabel12;

	private javax.swing.JLabel jLabel14;

	private javax.swing.JLabel jLabel15;

	private javax.swing.JLabel jLabel16;

	private javax.swing.JLabel jLabel17;

	private javax.swing.JLabel jLabel18;

	private javax.swing.JLabel jLabel2;

	private javax.swing.JLabel jLabel21;

	private javax.swing.JLabel jLabel23;

	private javax.swing.JLabel jLabel24;

	private javax.swing.JLabel jLabel26;

	private javax.swing.JLabel jLabel27;

	private javax.swing.JLabel jLabel28;

	private javax.swing.JLabel jLabel29;

	private javax.swing.JLabel jLabel3;

	private javax.swing.JLabel jLabel30;

	private javax.swing.JLabel jLabel31;

	private javax.swing.JLabel jLabel32;

	private javax.swing.JLabel jLabel33;

	private javax.swing.JLabel jLabel4;

	private javax.swing.JLabel jLabel6;

	private javax.swing.JLabel jLabel7;

	private javax.swing.JLabel jLabel8;

	private javax.swing.JScrollPane jScrollPane1;

	private javax.swing.JScrollPane jScrollPane2;

	private IntegerTextField jTextHoeheLi;

	private IntegerTextField jTextHoeheRe;

	private javax.swing.JTextField jTextPktNrLi;

	private javax.swing.JTextField jTextPktNrRe;

	private DoubleTextField jTextQuerLiGleis;

	private DoubleTextField jTextQuerPktLi;

	private DoubleTextField jTextQuerReGleis;

	private DoubleTextField jTextStationLi;

	private DoubleTextField jTextStationRe;

	private DoubleTextField jTextStationWeiche;

	private javax.swing.JTextField jTextWeichenBez;

	private javax.swing.JTextField jTextWeichenNr;

	private LageskizzenGVPTable tableGVP;

	private LageskizzenWeichenTable tableWeiche;

	private javax.swing.JSeparator jSeparator1;

	private javax.swing.JSeparator jSeparator2;

	private javax.swing.JSeparator jSeparator3;

	private javax.swing.JSeparator jSeparator4;

	private javax.swing.JSeparator jSeparator5;

	@Override
	public void focusGained(FocusEvent e) {

	}

	@Override
	public void focusLost(FocusEvent e) {

	}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.getSource() == tableGVP) {
			if (e.getKeyCode() == KeyEvent.VK_DELETE) {
				deleteSelectedRowGVP();
			}
		} else if (e.getSource() == tableWeiche) {
			if (e.getKeyCode() == KeyEvent.VK_DELETE) {
				deleteSelectedRowWeiche();
			}
		} else if (e.getSource() == jButtonCancel) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				jButtonCancel.doClick();
			}
		} else if (e.getSource() == jButtonOK) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				jButtonOK.doClick();
			}
		} else if (e.getSource() == jButtonNextGVP) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				jButtonNextGVP.doClick();
			}
		} else if (e.getSource() == jButtonNextWeiche) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				jButtonNextWeiche.doClick();
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent arg0) {

	}

	@Override
	public void keyTyped(KeyEvent arg0) {

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// bei Doppelklick auf eine Zeile in der Tabelle die Daten des
		// zugehörigen Elements in den Eingabefeldern anzeigen
		if (e.getClickCount() == 2) {
			if (e.getSource() == tableGVP) {
				int row = tableGVP.rowAtPoint(e.getPoint());
				gvpElement2Edit = tableGVP.getElementAtRow(row);
				if (gvpElement2Edit != null) {
					loadGVPElement(gvpElement2Edit);
				}
			} else if (e.getSource() == tableWeiche) {
				int row = tableWeiche.rowAtPoint(e.getPoint());
				weichenElement2Edit = tableWeiche.getElementAtRow(row);
				if (weichenElement2Edit != null) {
					loadWeichenElement(weichenElement2Edit);
				}
			}
		}
	}

	/**
	 * Laden der Weichenelemente aus der XML
	 * 
	 * @param weichenDAO
	 */
	private void loadWeichenElement(LageskizzenWeichenDAO weichenDAO) {
		jTextWeichenNr.setText("");
		if (weichenDAO.getnummerWeiche() != null) {
			jTextWeichenNr.setText(weichenDAO.getnummerWeiche());
		}
		jTextStationWeiche.setValue(weichenDAO.getstationWeiche());
		jTextWeichenBez.setText(weichenDAO.getbezWeiche());
	}

	/**
	 * Laden der GVP-Elemente aus der XML
	 * 
	 * @param gvpdao
	 */
	private void loadGVPElement(LageskizzenGVPDAO gvpdao) {
		jTextHoeheLi.setText("");
		if (gvpdao.gethoehenmaßGVPLinks() != 0) {
			jTextHoeheLi.setValue(gvpdao.gethoehenmaßGVPLinks());
		} else {
			jTextHoeheLi.setText("-");
		}
		jTextHoeheRe.setText("");
		if (gvpdao.gethoehenmaßGVPRechts() != 0) {
			jTextHoeheRe.setValue(gvpdao.gethoehenmaßGVPRechts());
		} else {
			jTextHoeheRe.setText("-");
		}
		jTextPktNrLi.setText("");
		if (gvpdao.getpunktNrGVPLinks() != null) {
			jTextPktNrLi.setText(gvpdao.getpunktNrGVPLinks());
		}
		jTextPktNrRe.setText("");
		if (gvpdao.getpunktNrGVPRechts() != null) {
			jTextPktNrRe.setText(gvpdao.getpunktNrGVPRechts());
		}
		jTextQuerLiGleis.setText("");
		if (gvpdao.getquerGleisLinks() != 0) {
			jTextQuerLiGleis.setValue(gvpdao.getquerGleisLinks());
		}
		jTextQuerPktLi.setText("");
		if (gvpdao.getquerGVPLinks() != 0) {
			jTextQuerPktLi.setValue(gvpdao.getquerGVPLinks());
		}
		jTextQuerReGleis.setText("");
		if (gvpdao.getquerGleisRechts() != 0) {
			jTextQuerReGleis.setValue(gvpdao.getquerGleisRechts());
		}
		jTextStationLi.setText("");
		if (gvpdao.getstationGVPLinks() != 0) {
			jTextStationLi.setValue(gvpdao.getstationGVPLinks());
		}
		jTextStationRe.setText("");
		if (gvpdao.getstationGVPRechts() != 0) {
			jTextStationRe.setValue(gvpdao.getstationGVPRechts());
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {

	}

	@Override
	public void mouseExited(MouseEvent arg0) {

	}

	@Override
	public void mousePressed(MouseEvent arg0) {

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {

	}
}
